package team.sun.sss.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.context.support.HttpRequestHandlerServlet;
import team.sun.sss.dao.student.StudentDao;
import team.sun.sss.dao.sturoutine.SrLeaveDao;
import team.sun.sss.dao.sturoutine.SrStaycomeDao;
import team.sun.sss.pojo.user.User;
import team.sun.sss.pojo.sturoutine.SrLeave;
import team.sun.sss.pojo.sturoutine.SrStaycome;


import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@Controller
public class StudentRoutineController {
    @Autowired
    SrLeaveDao srLeaveDao;
    @Autowired
    SrStaycomeDao srStaycomeDao;
    @Autowired
    StudentDao studentDao;

    //获取到申请表信息和学生信息
    @RequestMapping("/sr_come")
    public String srCome(Model model, HttpSession session, @RequestParam(required = false, defaultValue = "1", value = "pageNum") Integer pageNum,
                         @RequestParam(defaultValue = "5", value = "pageSize") Integer pageSize) {
        if (pageNum == null) {
            pageNum = 1;   //设置默认当前页
        }
        if (pageNum <= 0) {
            pageNum = 1;
        }
        if (pageSize == null) {
            pageSize = 5;    //设置默认每页显示的数据数
        }
        //1.引入分页插件,pageNum是第几页，pageSize是每页显示多少条,默认查询总数count
        PageHelper.startPage(pageNum, pageSize);
        //2.紧跟的查询就是一个分页查询-必须紧跟.后面的其他查询不会被分页，除非再次调用PageHelper.startPage
        try {
            User user = (User) session.getAttribute("loginInfo");
            List<SrStaycome> getStaycomeList = srStaycomeDao.getStuComeList(user.getUserId());
            model.addAttribute("getComeList", getStaycomeList);

            System.out.println("分页数据：" + getStaycomeList);
            PageInfo<SrStaycome> pageInfo = new PageInfo<SrStaycome>(getStaycomeList, pageSize);
            //4.使用model/map/modelandview等带回前端
            model.addAttribute("pageInfo", pageInfo);
        } finally {
            PageHelper.clearPage();
        }
        return "sturoutine/sr_come";
    }


    //管理员审核获取学生返校信息
    @RequestMapping("/staffCheckCome")
    public String staffCheckCome(Model model, @RequestParam(required = false, defaultValue = "1", value = "pageNum") Integer pageNum,
                                 @RequestParam(defaultValue = "5", value = "pageSize") Integer pageSize) {
        if (pageNum == null) {
            pageNum = 1;   //设置默认当前页
        }
        if (pageNum <= 0) {
            pageNum = 1;
        }
        if (pageSize == null) {
            pageSize = 5;    //设置默认每页显示的数据数
        }
        //1.引入分页插件,pageNum是第几页，pageSize是每页显示多少条,默认查询总数count
        PageHelper.startPage(pageNum, pageSize);
        //2.紧跟的查询就是一个分页查询-必须紧跟.后面的其他查询不会被分页，除非再次调用PageHelper.startPage
        try {
            List<SrStaycome> getStaffComeList = srStaycomeDao.getStaffComeList();
            model.addAttribute("getStaffComeList", getStaffComeList);//获得学生相关信息

            System.out.println("分页数据：" + getStaffComeList);
            PageInfo<SrStaycome> pageInfo = new PageInfo<SrStaycome>(getStaffComeList, pageSize);
            //4.使用model/map/modelandview等带回前端
            model.addAttribute("pageInfo", pageInfo);
        } finally {
            PageHelper.clearPage();
        }
        return "sturoutine/staffCheckCome";
    }


    //管理员审核学生申请信息
    @RequestMapping("/to_staff_checkCome/{num}/{stuId}")
    public String to_staff_checkCome(@PathVariable("num") int num, @PathVariable("stuId") int stuId, Model model) {

        model.addAttribute("StuComeList", studentDao.selectStuById(stuId));//获取学生信息
        model.addAttribute("staffComeList", srStaycomeDao.getSrComeList(num));//获取学生申请信息


        return "sturoutine/staffCheckCome_update";
    }

    @RequestMapping("/staffCheckCome_update")
    public void staffCheckCome_update(String staycomeState, int num, HttpRequestHandlerServlet
            req, HttpServletResponse resp) {

        srStaycomeDao.staffUpdateCome(staycomeState, num);

        try {
            resp.sendRedirect("/staffCheckCome");
        } catch (IOException e) {
            e.printStackTrace();
        }//java重定向，HTTP302

    }

    @RequestMapping("/staffCheckCome_select")//管理员查询学生返校信息（申请时间）
    public String staffCheckCome_select(Model model, String staycomeTime) {
        List<SrStaycome> getStaffComeList = srStaycomeDao.getStaffComeList();
        model.addAttribute("getStaffComeList2", getStaffComeList);//获得学生相关信息

        model.addAttribute("getStaffComeList", srStaycomeDao.getComeSelect(staycomeTime));
        return "sturoutine/staffCheckCome2";
    }

    //获得学生具体信息
    @GetMapping("/sr_come_detail/{num}")
    public String sr_come_detail(@PathVariable("num") int num, HttpSession session, Model model) {
        User user = (User) session.getAttribute("loginInfo");

        model.addAttribute("getStucomeList", studentDao.selectStuById(user.getUserId()));//获得学生相关信息
        model.addAttribute("getComeList", srStaycomeDao.getSrComeList(num));

        return "sturoutine/sr_come_detail";
    }


    //获取申请表信息（返校）
    @RequestMapping("/to_sr_come_update/{num}")
    public String to_sr_come_update(@PathVariable("num") int num, HttpSession session, Model model) {
        User user = (User) session.getAttribute("loginInfo");
        model.addAttribute("getStucomeList2", studentDao.selectStuById(user.getUserId()));
        model.addAttribute("getComeList2", srStaycomeDao.getSrComeList(num));
        return "sturoutine/sr_come_update";
    }

    //修改并保存申请信息（返校）
    @RequestMapping("/sr_come_update")
    public void sr_come_update(HttpSession session, Model
            model, @ModelAttribute(value = "getComeList") SrStaycome srStaycome, String StaycomeTime, String StaycomeReason,
                                 int num,HttpRequestHandlerServlet
                                             req, HttpServletResponse resp) {

        User user = (User) session.getAttribute("loginInfo");
        srStaycomeDao.updateCome(StaycomeTime, StaycomeReason, num);
        try {
            resp.sendRedirect("/sr_come");
        } catch (IOException e) {
            e.printStackTrace();
        }//java重定向，HTTP302
//        model.addAttribute("getComeList", srStaycomeDao.getComeList(user.getUserId()));
//        return "sturoutine/sr_come";
    }


    //获取学生信息
    @RequestMapping("/to_sr_come_insert")
    public String to_sr_come_insert(HttpSession session, Model model) {
        User user = (User) session.getAttribute("loginInfo");
        model.addAttribute("getStucomeList3", studentDao.selectStuById(user.getUserId()));
        model.addAttribute("getComeList3", srStaycomeDao.getComeList(user.getUserId()));
        return "sturoutine/sr_come_insert";
    }

    //创建学生申请信息（获取学生部分信息）
    @RequestMapping("/sr_come_insert")
    public void sr_come_insert(HttpSession session, Model model, String staycomeTime, String staycomeReason, HttpRequestHandlerServlet
            req, HttpServletResponse resp) {
        User user = (User) session.getAttribute("loginInfo");
        srStaycomeDao.addSrCome(user.getUserId(), staycomeTime, staycomeReason);

        try {
            resp.sendRedirect("/sr_come");
        } catch (IOException e) {
            e.printStackTrace();
        }//java重定向，HTTP302
//        return "sturoutine/sr_come";
    }


    //删除学生申请信息
    @GetMapping("/sr_come_delete/{num}")
    public void sr_come_delete(@PathVariable("num") int num, HttpSession session, Model model, HttpRequestHandlerServlet
            req, HttpServletResponse resp) {
        User user = (User) session.getAttribute("loginInfo");
        srStaycomeDao.deleteSrStaycome(num);
        try {
            resp.sendRedirect("/sr_come");
        } catch (IOException e) {
            e.printStackTrace();
        }//java重定向，HTTP302
//        model.addAttribute("getStucomeList", studentDao.selectStuById(user.getUserId()));
//        model.addAttribute("getComeList", srStaycomeDao.getSrComeList(num));
//        return "sturoutine/sr_come";
    }


    //获取学生留校信息
    @RequestMapping("/sr_stay")
    public String srStay(Model model, HttpSession
            session, @RequestParam(required = false, defaultValue = "1", value = "pageNum") Integer pageNum,
                         @RequestParam(defaultValue = "5", value = "pageSize") Integer pageSize) {
        if (pageNum == null) {
            pageNum = 1;   //设置默认当前页
        }
        if (pageNum <= 0) {
            pageNum = 1;
        }
        if (pageSize == null) {
            pageSize = 5;    //设置默认每页显示的数据数
        }
        //1.引入分页插件,pageNum是第几页，pageSize是每页显示多少条,默认查询总数count
        PageHelper.startPage(pageNum, pageSize);
        //2.紧跟的查询就是一个分页查询-必须紧跟.后面的其他查询不会被分页，除非再次调用PageHelper.startPage
        try {
            User user = (User) session.getAttribute("loginInfo");
            List<SrStaycome> getStaycomeList = srStaycomeDao.getStuStayList(user.getUserId());
            model.addAttribute("getStayList", getStaycomeList);

            System.out.println("分页数据：" + getStaycomeList);
            PageInfo<SrStaycome> pageInfo = new PageInfo<SrStaycome>(getStaycomeList, pageSize);
            //4.使用model/map/modelandview等带回前端
            model.addAttribute("pageInfo", pageInfo);
        } finally {
            PageHelper.clearPage(); //清理 ThreadLocal 存储的分页参数,保证线程安全
        }
        return "sturoutine/sr_stay";
    }

    //管理员获取学生留校信息
    @RequestMapping("/staffCheckStay")
    public String staffCheckStay(Model model, @RequestParam(required = false, defaultValue = "1", value = "pageNum") Integer pageNum,
                                 @RequestParam(defaultValue = "5", value = "pageSize") Integer pageSize) {
        if (pageNum == null) {
            pageNum = 1;   //设置默认当前页
        }
        if (pageNum <= 0) {
            pageNum = 1;
        }
        if (pageSize == null) {
            pageSize = 5;    //设置默认每页显示的数据数
        }
        //1.引入分页插件,pageNum是第几页，pageSize是每页显示多少条,默认查询总数count
        PageHelper.startPage(pageNum, pageSize);
        //2.紧跟的查询就是一个分页查询-必须紧跟.后面的其他查询不会被分页，除非再次调用PageHelper.startPage
        try {
            List<SrStaycome> getStaffStayList = srStaycomeDao.getStaffStayList();
            model.addAttribute("getStaffStayList", getStaffStayList);//获得学生相关信息
            System.out.println("分页数据：" + getStaffStayList);
            PageInfo<SrStaycome> pageInfo = new PageInfo<SrStaycome>(getStaffStayList, pageSize);
            //4.使用model/map/modelandview等带回前端
            model.addAttribute("pageInfo", pageInfo);
        } finally {
            PageHelper.clearPage(); //清理 ThreadLocal 存储的分页参数,保证线程安全
        }
        return "sturoutine/staffCheckStay";
    }

    //管理员审核学生申请信息
    @RequestMapping("/to_staff_checkStay/{num}/{stuId}")
    public String to_staff_checkStay(@PathVariable("num") int num, @PathVariable("stuId") int stuId, Model model) {

        model.addAttribute("StuStayList", studentDao.selectStuById(stuId));//获取学生信息
        model.addAttribute("staffStayList", srStaycomeDao.getSrStayList(num));//获取学生申请信息


        return "sturoutine/staffCheckStay_update";
    }


    @RequestMapping("/staffCheckStay_update")
    public void staffCheckStay_update(String staycomeState, int num, HttpRequestHandlerServlet
            req, HttpServletResponse resp) {
        srStaycomeDao.staffUpdateStay(staycomeState, num);
        try {
            resp.sendRedirect("/staffCheckStay");
        } catch (IOException e) {
            e.printStackTrace();
        }//java重定向，HTTP302
    }

    @RequestMapping("/staffCheckStay_select")//管理员查询学生留校信息（申请时间）
    public String staffCheckStay_select(Model model, String staycomeTime) {
        List<SrStaycome> getStaffStayList = srStaycomeDao.getStaffStayList();
        model.addAttribute("getStaffStayList2", getStaffStayList);//获得学生相关信息

        model.addAttribute("getStaffStayList", srStaycomeDao.getStaySelect(staycomeTime));
        return "sturoutine/staffCheckStay2";
    }

    //获取学生信息和学生申请留校信息
    @GetMapping("/sr_stay_detail/{num}")
    public String sr_stay_detail(@PathVariable("num") int num, HttpSession session, Model model) {
        User user = (User) session.getAttribute("loginInfo");

        model.addAttribute("getStustayList", studentDao.selectStuById(user.getUserId()));
        model.addAttribute("getStayList", srStaycomeDao.getSrStayList(num));
        return "sturoutine/sr_stay_detail";
    }

    //获取学生信息和学生申请留校信息
    @RequestMapping("/to_sr_stay_update/{num}")
    public String to_sr_stay_update(@PathVariable("num") int num, HttpSession session, Model model) {
        User user = (User) session.getAttribute("loginInfo");

        model.addAttribute("getStustayList2", studentDao.selectStuById(user.getUserId()));
        model.addAttribute("getStayList2", srStaycomeDao.getSrStayList(num));
        return "sturoutine/sr_stay_update";
    }

    //修改并保存学生留校信息
    @RequestMapping("/sr_stay_update")
    public void sr_stay_update(HttpSession session, Model
            model, @ModelAttribute(value = "getStayList") SrStaycome srStaycome, String StaycomeTime, String StaycomeReason,
                                 int num,HttpRequestHandlerServlet
                                           req, HttpServletResponse resp) {
        User user = (User) session.getAttribute("loginInfo");
        srStaycomeDao.updateStay(StaycomeTime, StaycomeReason, num);
        try {
            resp.sendRedirect("/sr_stay");
        } catch (IOException e) {
            e.printStackTrace();
        }//java重定向，HTTP302
//        model.addAttribute("getStayList", srStaycomeDao.getStayList(user.getUserId()));
//        return "sturoutine/sr_stay";
    }

    //获取学生信息
    @RequestMapping("/to_sr_stay_insert")
    public String to_sr_stay_insert(HttpSession session, Model model) {
        User user = (User) session.getAttribute("loginInfo");
        model.addAttribute("getStustayList3", studentDao.selectStuById(user.getUserId()));
        model.addAttribute("getStayList3", srStaycomeDao.getStayList(user.getUserId()));
        return "sturoutine/sr_stay_insert";
    }

    //创建学生申请留校信息（获取学生部分信息）
    @RequestMapping("/sr_stay_insert")
    public void sr_stay_insert(HttpSession session, Model model, String staycomeTime, String staycomeReason, HttpRequestHandlerServlet
            req, HttpServletResponse resp) {
        User user = (User) session.getAttribute("loginInfo");
        srStaycomeDao.addSrStay(user.getUserId(), staycomeTime, staycomeReason);
        try {
            resp.sendRedirect("/sr_stay");
        } catch (IOException e) {
            e.printStackTrace();
        }//java重定向，HTTP302


    }

    //删除（撤回）学生留校信息
    @GetMapping("/sr_stay_delete/{num}")
    public void sr_stay_delete(@PathVariable("num") int num, HttpSession session, Model model, HttpRequestHandlerServlet
            req, HttpServletResponse resp) {
        User user = (User) session.getAttribute("loginInfo");
        srStaycomeDao.deleteSrStaycome(num);
        try {
            resp.sendRedirect("/sr_stay");
        } catch (IOException e) {
            e.printStackTrace();
        }//java重定向，HTTP302
//        model.addAttribute("getStustayList", studentDao.selectStuById(user.getUserId()));
//        model.addAttribute("getStayList", srStaycomeDao.getSrStayList(num));

//        return "sturoutine/sr_stay";
    }


    //获取学生请假信息
    @RequestMapping("/sr_leave")
    public String srLeave(Model model, HttpSession
            session, @RequestParam(required = false, defaultValue = "1", value = "pageNum") Integer pageNum,
                          @RequestParam(defaultValue = "5", value = "pageSize") Integer pageSize) {
        if (pageNum == null) {
            pageNum = 1;   //设置默认当前页
        }
        if (pageNum <= 0) {
            pageNum = 1;
        }
        if (pageSize == null) {
            pageSize = 5;    //设置默认每页显示的数据数
        }
        //1.引入分页插件,pageNum是第几页，pageSize是每页显示多少条,默认查询总数count
        PageHelper.startPage(pageNum, pageSize);
        //2.紧跟的查询就是一个分页查询-必须紧跟.后面的其他查询不会被分页，除非再次调用PageHelper.startPage
        try {
            User user = (User) session.getAttribute("loginInfo");
            List<SrLeave> getSrLeaveList = srLeaveDao.getSrLeaveList(user.getUserId());
            model.addAttribute("getSrLeaveList", getSrLeaveList);

            System.out.println("分页数据：" + getSrLeaveList);
            PageInfo<SrLeave> pageInfo = new PageInfo<SrLeave>(getSrLeaveList, pageSize);
            //4.使用model/map/modelandview等带回前端
            model.addAttribute("pageInfo", pageInfo);
        } finally {
            PageHelper.clearPage(); //清理 ThreadLocal 存储的分页参数,保证线程安全
        }

        return "sturoutine/sr_leave";
    }

    //管理员获取学生请假信息
    @RequestMapping("/staffCheckLeave")
    public String staffCheckLeave(Model model, @RequestParam(required = false, defaultValue = "1", value = "pageNum") Integer pageNum,
                                  @RequestParam(defaultValue = "5", value = "pageSize") Integer pageSize) {
        if (pageNum == null) {
            pageNum = 1;   //设置默认当前页
        }
        if (pageNum <= 0) {
            pageNum = 1;
        }
        if (pageSize == null) {
            pageSize = 5;    //设置默认每页显示的数据数
        }
        //1.引入分页插件,pageNum是第几页，pageSize是每页显示多少条,默认查询总数count
        PageHelper.startPage(pageNum, pageSize);
        //2.紧跟的查询就是一个分页查询-必须紧跟.后面的其他查询不会被分页，除非再次调用PageHelper.startPage
        try {
            List<SrLeave> getStaffLeaveList = srLeaveDao.getStaffLeaveList();
            model.addAttribute("getStaffLeaveList", getStaffLeaveList);//获得学生相关信息

            System.out.println("分页数据：" + getStaffLeaveList);
            PageInfo<SrLeave> pageInfo = new PageInfo<SrLeave>(getStaffLeaveList, pageSize);
            //4.使用model/map/modelandview等带回前端
            model.addAttribute("pageInfo", pageInfo);
        } finally {
            PageHelper.clearPage(); //清理 ThreadLocal 存储的分页参数,保证线程安全
        }
        return "sturoutine/staffCheckLeave";
    }

    //管理员审核学生申请信息
    @RequestMapping("/to_staff_checkLeave/{num}/{stuId}")
    public String to_staff_checkLeave(@PathVariable("num") int num, @PathVariable("stuId") int stuId, Model model) {

        model.addAttribute("StuleaveList", studentDao.selectStuById(stuId));//获取学生信息
        model.addAttribute("staffLeaveList", srLeaveDao.getLeaveList(num));//获取学生申请信息


        return "sturoutine/staffCheckLeave_update";
    }


    //管理员审批并返回至表格
    @RequestMapping("/staffCheckLeave_update")
    public void staffCheckLeave_update(String LeaveApplystate, int num, HttpRequestHandlerServlet
            req, HttpServletResponse resp) {
        srLeaveDao.staffUpdateLeave(LeaveApplystate, num);
        try {
            resp.sendRedirect("/staffCheckLeave");
        } catch (IOException e) {
            e.printStackTrace();
        }//java重定向，HTTP302
    }

    @RequestMapping("/staffCheckLeave_select")//管理员查询学生请假信息（申请时间）
    public String staffCheckLeave_select(Model model, String leaveApplytime) {
        List<SrLeave> getStaffLeaveList = srLeaveDao.getStaffLeaveList();
        model.addAttribute("getStaffLeaveList2", getStaffLeaveList);//获得学生相关信息
        model.addAttribute("getStaffLeaveList", srLeaveDao.getLeaveSelect(leaveApplytime));
        return "sturoutine/staffCheckLeave2";
    }


    //教师获取学生请假信息
    @RequestMapping("/instructor_leave")
    public String instructor_leave(Model model, @RequestParam(required = false, defaultValue = "1", value = "pageNum") Integer pageNum,
                                   @RequestParam(defaultValue = "5", value = "pageSize") Integer pageSize) {
        if (pageNum == null) {
            pageNum = 1;   //设置默认当前页
        }
        if (pageNum <= 0) {
            pageNum = 1;
        }
        if (pageSize == null) {
            pageSize = 5;    //设置默认每页显示的数据数
        }
        //1.引入分页插件,pageNum是第几页，pageSize是每页显示多少条,默认查询总数count
        PageHelper.startPage(pageNum, pageSize);
        //2.紧跟的查询就是一个分页查询-必须紧跟.后面的其他查询不会被分页，除非再次调用PageHelper.startPage
        try {
            List<SrLeave> getInsLeaveList = srLeaveDao.getInsLeaveList();
            model.addAttribute("getInsLeaveList", getInsLeaveList);//获得学生相关信息

            System.out.println("分页数据：" + getInsLeaveList);
            PageInfo<SrLeave> pageInfo = new PageInfo<SrLeave>(getInsLeaveList, pageSize);
            //4.使用model/map/modelandview等带回前端
            model.addAttribute("pageInfo", pageInfo);
        } finally {
            PageHelper.clearPage(); //清理 ThreadLocal 存储的分页参数,保证线程安全
        }
        return "sturoutine/instructor_leave";
    }

    //教师审核学生申请信息
    @RequestMapping("/to_instructorUpdate_leave/{num}/{stuId}")
    public String to_instructorUpdate_leave(@PathVariable("num") int num, @PathVariable("stuId") int stuId, Model
            model) {

        model.addAttribute("StuleaveList", studentDao.selectStuById(stuId));//获取学生信息
        model.addAttribute("InsLeaveList", srLeaveDao.getLeaveList(num));//获取学生申请信息


        return "sturoutine/instructorUpdate_leave";
    }

    //教师审批并返回至表格
    @RequestMapping("/instructorUpdate_leave")
    public void instructorUpdate_leave(String LeaveApplystate, int num, HttpRequestHandlerServlet
            req, HttpServletResponse resp) {
        srLeaveDao.InsUpdateLeave(LeaveApplystate, num);
        try {
            resp.sendRedirect("/instructor_leave");
        } catch (IOException e) {
            e.printStackTrace();
        }//java重定向，HTTP302
    }

    @RequestMapping("/instructor_leave_select")//辅导员查询学生请假信息（申请时间）
    public String instructor_leave_select(Model model, String leaveApplytime) {
        List<SrLeave> getInsLeaveList = srLeaveDao.getInsLeaveList();
        model.addAttribute("getInsLeaveList2", getInsLeaveList);//获得学生相关信息
        model.addAttribute("getInsLeaveList", srLeaveDao.getLeaveSelect(leaveApplytime));
        return "sturoutine/instructor_leave2";
    }


    //获取学生信息和学生申请请假信息
    @GetMapping("/sr_leave_detail/{num}")
    public String sr_leave_detail(@PathVariable("num") int num, HttpSession session, Model model) {
        User user = (User) session.getAttribute("loginInfo");

        model.addAttribute("getStuleaveList", studentDao.selectStuById(user.getUserId()));
        model.addAttribute("getLeaveList", srLeaveDao.getLeaveList(num));
        return "sturoutine/sr_leave_detail";
    }

    //查询学生申请信息（请假）
    @RequestMapping("/to_sr_leave_update/{num}")
    public String to_sr_leave_create(@PathVariable("num") int num, HttpSession session, Model model) {
        User user = (User) session.getAttribute("loginInfo");
        model.addAttribute("getStuleaveList2", studentDao.selectStuById(user.getUserId()));
        model.addAttribute("getLeaveList2", srLeaveDao.getLeaveList(num));
        return "sturoutine/sr_leave_update";
    }

    //修改并保存学生申请信息（请假）
    @RequestMapping("/sr_leave_update")
    public void sr_leave_create(HttpSession session, Model
            model, @ModelAttribute(value = "getSrLeaveList") SrLeave srLeave, String LeaveReason, String
                                          LeaveDestination, String LeaveApplytime, String LeaveTime, String LeaveTime2,int num, HttpRequestHandlerServlet
            req, HttpServletResponse resp) {
        User user = (User) session.getAttribute("loginInfo");
        srLeaveDao.updateLeave(LeaveReason, LeaveDestination, LeaveApplytime, LeaveTime,LeaveTime2,num);
        try {
            resp.sendRedirect("/sr_leave");
        } catch (IOException e) {
            e.printStackTrace();
        }//java重定向，HTTP302
//        model.addAttribute("getSrLeaveList", srLeaveDao.getSrLeaveList(user.getUserId()));
//        return "sturoutine/sr_leave";

    }

    //获取学生信息和学生申请请假信息
    @RequestMapping("/to_sr_leave_insert")
    public String to_sr_leave_insert(HttpSession session, Model model) {
        User user = (User) session.getAttribute("loginInfo");
        model.addAttribute("getStuleaveList3", studentDao.selectStuById(user.getUserId()));
        model.addAttribute("getLeaveList3", srLeaveDao.getLeaveList(user.getUserId()));
        return "sturoutine/sr_leave_insert";
    }

    @RequestMapping("/sr_leave_insert")
    public void sr_leave_insert(HttpSession session, Model model, String leaveReason, String
            leaveDestination, String leaveApplytime, String leaveTime,String leaveTime2, HttpRequestHandlerServlet
                                        req, HttpServletResponse resp) {
        User user = (User) session.getAttribute("loginInfo");
        srLeaveDao.addSrLeave(user.getUserId(),leaveReason,leaveDestination,leaveApplytime,leaveTime,leaveTime2);
        try {
            resp.sendRedirect("/sr_leave");
        } catch (IOException e) {
            e.printStackTrace();
        }//java重定向，HTTP302

    }


    //删除（撤回）请假申请
    @GetMapping("/sr_leave_delete/{num}")
    public void sr_leave_delete(@PathVariable("num") int num, HttpSession session, Model model, HttpRequestHandlerServlet
            req, HttpServletResponse resp) {
        User user = (User) session.getAttribute("loginInfo");
        srLeaveDao.deleteSrLeave(num);
        try {
            resp.sendRedirect("/sr_leave");
        } catch (IOException e) {
            e.printStackTrace();
        }//java重定向，HTTP302
//        model.addAttribute("getStuleaveList", studentDao.selectStuById(user.getUserId()));
//        model.addAttribute("getLeaveList", srLeaveDao.getLeaveList(num));

//        return "sturoutine/sr_leave";
    }


}
